package com.pyb.java.commonutil.utils;

import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegularUtils {

    /**
     * true  合适
     * fasle 正则不通过
     * @param mobiles
     * @return
     */
    public static boolean isMobile(String mobiles) {

        String telRegex = "^1+[3456789]+\\d{9}$";
        if (TextUtils.isEmpty(mobiles)) {
            return false;
        } else {
            return mobiles.matches(telRegex);
        }
    }

    /**
     * true  合适
     * fasle 正则不通过
     *
     * @param mobile
     * @return
     */
    public static boolean isMobileNo(String mobile) {

        if (mobile.length() != 11) {
            return false;
        }

        String str = mobile;
        /**
         * 第一位是1，总长11位数字
         */
        String telRegex = "^(1)\\d{10}$";
        Pattern r = Pattern.compile(telRegex);
        Matcher m = r.matcher(str);

        return m.matches();

    }


    //不少于6位要求字母数字混排
    public static boolean isPwd(String pwd) {
        String pwdRegex = "^[a-zA-Z0-9]{6,16}$";
        boolean isLetter = false;
        boolean isDigit = false;
        if (TextUtils.isEmpty(pwdRegex)) {
            return false;
        } else {
            for (int i = 0; i < pwd.length(); i++) {
                if (Character.isLetter(pwd.charAt(i))) {
                    isLetter = true;
                } else if (Character.isDigit(pwd.charAt(i))) {
                    isDigit = true;
                }
            }
            return pwd.matches(pwdRegex) && isDigit && isLetter;
        }
    }
}
